{us/mf/mfdtitle.i}


define variable vc_rcnbr like prh_receiver.
define variable vc_ponbr like prh_nbr.
define variable vc_cipnbr as char.
define variable errorst     as   character   no-undo.
define variable errornum    as   integer     no-undo.
define variable l_msg1      like msg_desc    no-undo.


     
for each prh_hist no-lock where prh_hist.prh_domain = global_domain
                            and prh_hist.prh_type = "M"
                            and (not can-find(first xxcipd_det where xxcipd_receiver = prh_hist.prh_receiver
                                                                 and xxcipd_line  = prh_hist.prh_line
                                                                 and xxcipd_domain = global_domain
                                                                 no-lock))                                                                
                            .
                            
    for first tr_hist no-lock where tr_domain = global_domain
                               and tr_effdate = prh_hist.prh_rcp_date
                               and tr_lot = prh_hist.prh_receiver
                               and tr_line = prh_hist.prh_line
                               ,
               each trgl_det no-lock where trgl_det.trgl_domain = global_domain
                                       and trgl_det.trgl_trnbr = tr_hist.tr_trnbr.
                                       
       find code_mstr where code_domain = global_domain
                    and code_fldname = "xxcip"
                    and code_value begins "glcode"
                    and code_cmmt =  trgl_dr_acct 
                    no-lock no-error.
       if available code_mstr then
       do:


    for first pod_det where pod_domain = global_domain
                    and pod_nbr  = prh_hist.prh_nbr
                    and pod_line = prh_hist.prh_line
                    no-lock.

      find si_mstr where si_domain = global_domain
                     and si_site = tr_hist.tr_site
                     no-lock no-error.                     

                      
        vc_cipnbr = "".
        
                {us/bbi/gprun.i ""gpnrmgv.p""
                "(""CIPNBR"",
                    input-output vc_cipnbr,
                    output errorst,
                    output errornum)"}.   
                  if errorst = "yes"
       then do:
              {us/bbi/pxmsg.i &msgnum=errornum &errorlevel=1 &msgbuffer=l_msg1}
       end.     
      create xxcipd_det.
      assign xxcipd_det.xxcipd_ciptrnbr       =  vc_cipnbr 
             xxcipd_det.xxcipd_cipid          = pod_det.pod_vpart
             xxcipd_det.xxcipd_year           = year(prh_hist.prh_rcp_date)
             xxcipd_det.xxcipd_period         = month(prh_hist.prh_rcp_date)
             xxcipd_det.xxcipd_trdate         = tr_hist.tr_effdate
             xxcipd_det.xxcipd_sysdate        = today
             xxcipd_det.xxcipd_effdate        = tr_hist.tr_effdate
             xxcipd_det.xxcipd_trtime         = tr_hist.tr_time
             xxcipd_det.xxcipd_userid         = global_userid
             xxcipd_det.xxcipd_domain         = global_domain
             xxcipd_det.xxcipd_entity         = si_mstr.si_entity
             xxcipd_det.xxcipd_voucher        = 0
             xxcipd_det.xxcipd_jouranlcode    = ""
             xxcipd_det.xxcipd_line           = prh_hist.prh_line
             xxcipd_det.xxcipd_desc           = ""
             xxcipd_det.xxcipd_dr_glcode      = trgl_det.trgl_dr_acct
             xxcipd_det.xxcipd_cr_glcode      = ""
             
             xxcipd_det.xxcipd_dr_costcentre  = trgl_det.trgl_dr_cc
             xxcipd_det.xxcipd_cr_costcentre  = ""
             xxcipd_det.xxcipd_dr_division    = trgl_det.trgl_dr_sub
             xxcipd_det.xxcipd_cr_division    = ""
             xxcipd_det.xxcipd_dr_project     = trgl_det.trgl_dr_proj
             xxcipd_det.xxcipd_cr_project     = ""
             xxcipd_det.xxcipd_dr_saf1        = ""
             xxcipd_det.xxcipd_cr_saf1        = ""
             xxcipd_det.xxcipd_dr_saf2        = ""
             xxcipd_det.xxcipd_cr_saf2        = ""
             xxcipd_det.xxcipd_dr_saf3        = ""
             xxcipd_det.xxcipd_cr_saf3        = ""
             
             xxcipd_det.xxcipd_dr_amt         = trgl_det.trgl_gl_amt
             xxcipd_det.xxcipd_cr_amt         = 0
             xxcipd_det.xxcipd_transnbr       = string(tr_hist.tr_trnbr)
             xxcipd_det.xxcipd_partnbr        = pod_det.pod_part
             xxcipd_det.xxcipd_partdesc       = pod_det.pod_desc
             xxcipd_det.xxcipd_quantity       = prh_hist.prh_rcvd
             xxcipd_det.xxcipd_price          = prh_hist.prh_pur_cost
             xxcipd_det.xxcipd_receiver       = prh_hist.prh_receiver
             xxcipd_det.xxcipd_currency       = prh_hist.prh_curr
             xxcipd_det.xxcipd_faid           = ""
             xxcipd_det.xxcipd_datafrom       = "PO"
             
             .

end. /* for each pod_mstr where pod_domain = global_domain */

end. /* for each prh_hist */
   end. /* for first tr_hist */
   
   end. /* for each prh_hist */
